package xyz.renyumeng.xkm.gateway.config;

import cn.dev33.satoken.reactor.filter.SaReactorFilter;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author renyumeng
 * @date Created in 12:33 2023/7/6
 */

public class SaTokenConfigure{
    @Bean
    public SaReactorFilter getSaServletFilter() {
        // 注册 Sa-Token 拦截器，校验规则为 StpUtil.checkLogin() 登录校验。
       return new SaReactorFilter()
               .addInclude("/**")
               .addExclude("/customer/user/register")
               .addExclude("/user/shop/product/search/**")
               .setAuth(obj->{
                   SaRouter
                           .match("/**","/customer/user/login",StpUtil::checkLogin);
               })
               .setError(e -> SaResult.error(e.getMessage()));
    }
}

